import static java.lang.System.*
import static java.util.Date.*
import static javax.swing.JOptionPane.*

if( textArea?.selectedText ){
    textArea.with{
        def selection = selection[0].clone()
        def isEndEnter = selectedText[-1] =~ /\n\s*$/
        def oldtext = selectedText
        def newtext = ""
        def lines = selectedText.readLines()
        if( lines.findAll{ it =~ /^\s*\/\/.*/ }.size() == lines.size() ){
            println 0
            newtext = lines.collect{
                it.replaceAll(/(?<=^\s*)\/\//, "")
            }.join("\n")
        } else {
            newtext = lines.collect{
                "//" + it
            }.join("\n")
        }
        selectedText = newtext + (isEndEnter?"\n":"")
        addToSelection(new org.gjt.sp.jedit.textarea.Selection.Range(selection.start, selection.end + newtext.size() - oldtext.size()))
    }
}
